﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace JqueryNet.FormControl.FormWebControl
{
   public class JDropDownList: JWebControl
    {
        DropDownList dropDownList;

        public JDropDownList(DropDownList dropDownList)
            : base(dropDownList)
        {
            this.dropDownList = dropDownList;            
        }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "backcolor":
                    Value = dropDownList.BackColor.Name;
                    return;
                case "bordercolor":
                    Value = dropDownList.BorderColor.Name;
                    return;
                case "borderwidth":
                    Value = dropDownList.BorderWidth;
                    return;
                case "height":
                    Value = dropDownList.Height;
                    return; 
                case "css":
                case "cssclass":
                case "class":
                    Value = dropDownList.CssClass;
                    return;
                case "items":
                    Value = dropDownList.Items;
                    return;
                case "selectitem":
                    Value = dropDownList.SelectedItem;
                    return;
                case "selectvalue":
                    Value = dropDownList.SelectedValue;
                    return;
                case "text":
                    Value = dropDownList.Text;
                    return;
                case "tooltip":
                case "title":
                    Value = dropDownList.ToolTip;
                    return;
                case "selectedindex":
                case "index":
                    Value = dropDownList.SelectedIndex; return;
                case "width":
                    Value = dropDownList.Width;
                    return;
                default:
                    base.Attr(key); return;
            }

        }

        public override void Attr(string key, string value)
        {
            int b;
            int.TryParse(value, out b);
            switch (key.ToLower())
            {
                case "borderwidth":
                    dropDownList.BorderWidth = b;
                    return;
                case "height":
                    dropDownList.Height = b;return;
                case "css":
                case "cssclass":
                case "class":
                    dropDownList.CssClass = value;
                    return;
                case "selectvalue":
                    dropDownList.SelectedValue = value;
                    return;
                case "text":
                    dropDownList.Text = value;
                    return;
                case "tooltip":
                case "title":
                    dropDownList.ToolTip = value;
                    return;
                case "selectedindex":
                case "index":
                    dropDownList.SelectedIndex = b;
                    return;
                case "width":
                    dropDownList.Width = b;
                    return;
                default:
                    base.Attr(key, value); return;
            }

        }

        public override void Val()
        {
            Value = dropDownList.SelectedValue;
        }

        public override void Val(string value)
        {
            dropDownList.SelectedValue = value;
        }
 
    }
}
